package com.jay.tools.configure;

import android.content.Context;
import android.os.Handler;

import java.util.HashMap;

/**
 * Created by tan on 2017/9/13 013.
 * 对外的工具类，提供一系列的静态方法
 */

public final class Party {

    /**
     * 必须在Application中初始化
     *
     * @param context
     * @return
     */
    public static Configurator init(Context context) {
        getConfigurations().put(ConfigKeys.APPLICATION_CONTEXT, context.getApplicationContext());
        return Configurator.getInstance();
    }

    public static HashMap<Object, Object> getConfigurations() {
        return Configurator.getInstance().getLatteConfigs();
    }

    public static Configurator getInstance() {
        return Configurator.getInstance();
    }

    /**
     * 根据配置key获取相应的配置项
     *
     * @param key
     * @param <T>
     * @return
     */
    public static <T> T getValue(String key) {
        return getInstance().getConfigValue(key);
    }

    public static Context getApplicationContext() {
        return (Context) getConfigurations().get(ConfigKeys.APPLICATION_CONTEXT);
    }

    public static Handler getHandler() {
        return (Handler) getConfigurations().get(ConfigKeys.HANDLER);
    }

    public static Long getLoaderDelayed() {
        Object o = Party.getConfigurations().get(ConfigKeys.LOADER_DELAYED);
        if (null == o) {
            return 0l;
        }
        return (Long) o;
    }
}
